#!/bin/sh

if [ "$1" = "help" ]; then
    echo "*** Description ***" 
    echo "Updates all installed packages using system package manager"
    echo ""
    echo "*** Usage ***"
    echo "pkg-up"
    echo ""
    echo "*** Parameters ***"
    echo ""
    echo "*** Options ***"
    echo ""
    exit 0
fi

void () {
    if [ -f /usr/bin/xbps-install ]; then
        echo "Doing dry run"
        xbps-install -SuMyn "$@"
        echo "Finished dry run, continue?"
        doas xbps-install -SuM "$@"
        [ -f /usr/bin/xcheckrestart ] && xcheckrestart
        [ -f /bin/updatedb ] && doas updatedb
        exit 1
    fi
}

void "$@"
echo "Cannot determain package manager"
